package leetcode_301_400;

public class LeeCode_397 {
    public static void main(String[] args) {
        System.out.println(integerReplacement(7));
    }
    private static int integerReplacement(int n) {
        if (n == 1)
            return 0;
        if (n % 2 == 0){
            return 1 + integerReplacement(n / 2);
        }else {
            return 2 + Math.min(integerReplacement(n / 2), integerReplacement(n / 2 + 1));
        }
    }
}
